package com.zuimei.zuimei.widgets;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zuimei.zuimei.R;

/**
 * Created by Jogger on 2017/1/29.
 * 标题栏
 */

public class MyTitleBar extends RelativeLayout {
    private RelativeLayout rl_container;
    private LinearLayout ll_msg_container;
    private LinearLayout ll_time_container;
    private TextView tv_time;
    private LinearLayout ll_date_container;
    private TextView tv_time_day;
    private TextView tv_time_month;
    private TextView tv_time_week;
    private ImageView iv_title;
    private ImageButton ibtn_search;

    public MyTitleBar(Context context) {
        this(context, null);
    }

    public MyTitleBar(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MyTitleBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        View view = LayoutInflater.from(context).inflate(R.layout.app_title_layout, this, true);
        rl_container = (RelativeLayout) view.findViewById(R.id.rl_container);
        iv_title = (ImageView) view.findViewById(R.id.iv_title);
        ll_time_container = (LinearLayout) view.findViewById(R.id.ll_time_container);
        tv_time = (TextView) view.findViewById(R.id.tv_time);
        ll_msg_container = (LinearLayout) view.findViewById(R.id.ll_msg_container);
        ll_date_container = (LinearLayout) view.findViewById(R.id.ll_date_container);
        tv_time_day = (TextView) view.findViewById(R.id.tv_time_day);
        tv_time_month = (TextView) view.findViewById(R.id.tv_time_month);
        tv_time_week = (TextView) view.findViewById(R.id.tv_time_week);
        ibtn_search = (ImageButton) view.findViewById(R.id.ibtn_search);
        TypedArray typedArray = getResources().obtainAttributes(attrs, R.styleable.MyTitleBar);
        //int defColor = Color.parseColor("#009FD3");
        // int color = typedArray.getColor(R.styleable.MyTitleBar_background_color, defColor);
        //rl_container.setBackgroundColor(color);
        typedArray.recycle();
    }

    //设置信息（今日/昨日）
    public void setDateMsg(String msg) {
        if (!TextUtils.isEmpty(msg)) {
            tv_time.setText(msg);
        }
    }

    public void setTimeMonth(String month) {
        if (!TextUtils.isEmpty(month)) {
            tv_time_month.setText(month);
        }
    }

    public void setTimeWeek(String week) {
        if (!TextUtils.isEmpty(week)) {
            tv_time_week.setText(week);
        }
    }

    public void setTimeDay(String day) {
        if (!TextUtils.isEmpty(day)) {
            tv_time_day.setText(day);
        }
    }

    public String getTimeDay() {
        return tv_time_day.getText().toString();
    }

    //设置日期可见
    public void setDateContainerVisiable(int isVisiable) {
        ll_time_container.setVisibility(isVisiable);
        if (ll_time_container.getVisibility() == View.VISIBLE) {
            ll_msg_container.setVisibility(View.GONE);
            ibtn_search.setVisibility(View.GONE);
        }
    }

    //设置文字可见
    public void setMsgContainerVisiable(int isVisiable) {
        ll_msg_container.setVisibility(isVisiable);
        if (ll_msg_container.getVisibility() == View.VISIBLE) {
            ll_time_container.setVisibility(View.GONE);
            ibtn_search.setVisibility(View.GONE);
        }
    }

    //设置搜索按钮可见
    public void setSearchBtnVisiable(int isVisiable) {
        ibtn_search.setVisibility(isVisiable);
        if (ibtn_search.getVisibility() == View.VISIBLE) {
            ll_time_container.setVisibility(View.GONE);
            ll_msg_container.setVisibility(View.GONE);
        }
    }

}
